<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>初心博客后台管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link href="/plugins/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="/css/admin.css" rel="stylesheet">
</head>

<body>
    <div class="lyear-layout-web">
        <div class="lyear-layout-container">
               <!--左侧导航-->
               <% include sliderBar%>
               <!--End 左侧导航-->
               
               <!--头部信息-->
               <% include headerBar%>
               <!--End 头部信息-->

            <!--页面主要内容-->
            <main class="lyear-layout-content">

                <div class="container-fluid">


                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-toolbar clearfix">
                                    <form class="pull-right search-bar" method="get" action="/admin/search" role="form">
                                        <div class="input-group">
                                            <input type="text" class="form-control" value="" name="keyword" id="search-txt" placeholder="请输入名称">
                                            <div class="input-group-btn">
                                                <button class="btn btn-default" id="search-btn" type="button">搜索</button>
                                            </div>

                                        </div>
                                    </form>
                                    <div class="toolbar-btn-action">
                                        <a class="btn btn-primary m-r-5" href="/admin/addUser"><i class="mdi mdi-plus"></i> 新增</a>
                                    </div>
                                </div>
                                <div class="card-body">

                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>编号</th>
                                                    <th>用户名</th>
                                                    <th>邮箱</th>
                                                    <th>状态</th>
                                                    <th>头像</th>
                                                    <th>创建时间</th>
                                                    <th>操作</th>
                                                </tr>
                                            </thead>
                                            <tbody class="user-data">
                                                    <%users.forEach(function(user){%>
                                                        <tr>
                                                                <td><%=user.userId%></td>
                                                                <td><%=user.username%></td>
                                                                <td><%=user.email%></td>
                                                                <td>
                                                                    <%if(user.status){%>
                                                                        <font class="text-success">正常</font>
                                                                    <%}else{%>
                                                                        <font class="text-danger">禁用</font>
                                                                    <%}%>
                                                                    
                                                                </td>
                                                                <td><%=user.avatar%></td>
                                                                <td><%=user.createTime%></td>
                                                                <td>
                                                                    <div class="btn-group">
                                                                        <a class="btn btn-xs btn-default" href="/admin/editUser/<%=user.userId%>" title="" data-toggle="tooltip" data-original-title="编辑"><i class="mdi mdi-pencil"></i></a>
                                                                        <a class="btn btn-xs btn-default" href="/admin/deleteUser/<%=user.userId%>" title="" data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                    <%})%>
                                              

                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- 分页菜单 -->
                                    <div class="pagebox" style="text-align: right">

                                    </div>

                                </div>
                            </div>
                        </div>

                    </div>

                </div>

            </main>
            <!--End 页面主要内容-->
        </div>
    </div>

    <script type="text/javascript" src="/plugins/jquery/jquery-3.4.0.min.js"></script>
    <script type="text/javascript" src="/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/perfect-scrollbar.min.js"></script>
    <script src="/plugins/bootstrapPager.js"></script>
    <script type="text/javascript" src="/js/main.min.js"></script>
    <script>
        
        //后台用户页面
        var total = <%= total %>;
        var pagehtml = Pager({
            totalCount: total, //总条数为150
            pageSize: 5, //每页显示6条内容，默认10
            buttonSize: 6, //显示6个按钮，默认10
            pageParam: 'page', //页码的参数名为'p'，默认为'page'
            className: 'pagination', //分页的样式
            prevButton: '上一页', //上一页按钮
            nextButton: '下一页', //下一页按钮
            firstButton: '首页', //第一页按钮
            lastButton: '末页', //最后一页按钮
        })
        $('.pagebox').html(pagehtml)


        $('#search-btn').click(function(){
            var txt = $('#search-txt').val()
            $.post('/admin/searchUser',{search:txt},function(data){
                    console.log(data);
                    if(data.result=='空数据'){
                        location.href='/admin/listuser'
                        return;
                    }
                    showData(data)

                    $('#search-txt').val('')
                    showPagation('')
                 
                })
            function  showData(data) { 
                var html = '';
                for (var i = 0; i < data.length; i++) {
                    data[i].status = data[i].status ? '正常' : '禁用';       
                    html += `<tr>  
                                  
                <td>${data[i].userId}</td>
                <td>${data[i].username}</td>
                <td>${data[i].email}</td> 
                <td>${data[i].status}</td> 
                <td>${data[i].avatar}</td> 
                <td>${data[i].createTime}</td> 

                <td>
                   <div class="btn-group">
                        <a class="btn btn-xs btn-default" href="/admin/editUser/${data[i].userId}" title="" data-toggle="tooltip" data-original-title="编辑"><i class="mdi mdi-pencil"></i></a>
                        <a class="btn btn-xs btn-default" href="/admin/deleteUser/${data[i].userId}" title="" data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
                  </div>
                </td>
              </tr>`
                }
                $('.user-data').html(html);
                $('.pagebox').hide();
             }
        })
    </script>
</body>

</html>